import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export default {
  // 设置模式
  mode: 'development',
  // 入口文件
  entry: './main.ts',
  // 输出配置
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'main.js',
    module: true,
    chunkFormat: 'module'
  },
  target: ['node', 'es2020'],
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/
      }
    ]
  },
  // 解析配置
  resolve: {
    extensions: ['.tsx', '.ts', '.js', '.json'],
    alias: {
      '@': path.resolve(__dirname, 'src'),
    }
  },
  devtool: 'source-map',
  node: {
    __dirname: false,
    __filename: false,
    global: true
  },
  // 实验性功能
  experiments: {
    outputModule: true,
    topLevelAwait: true
  }
}; 
